package com.coda.mapper;

import com.coda.adminVo.apartment.ApartmentDetailVo;
import com.coda.adminVo.apartment.ApartmentItemVo;
import com.coda.adminVo.apartment.ApartmentQueryVo;
import com.coda.adminVo.fee.FeeValueVo;
import com.coda.adminVo.graph.GraphVo;
import com.coda.annotation.AutoFill;
import com.coda.entity.*;
import com.coda.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ApartmentMapper {
    /**
     * 插入公寓基本信息
     * @param apartmentInfo
     */
    @AutoFill(OperationType.INSERT)
    void insertApartmentInfo(ApartmentInfo apartmentInfo);

    /**
     * 插入公寓图片
     * @param graphInfoList
     */
    @AutoFill(OperationType.INSERT)
    void insertGraphInfo(@Param("graphInfoList") List<GraphInfo> graphInfoList);

    /**
     * 插入配套关系
     * @param apartmentFacilityList
     */
    @AutoFill(OperationType.INSERT)
    void insertAparFacility(@Param("apartmentFacilityList")List<ApartmentFacility> apartmentFacilityList);

    /**
     * 插入公寓和标签关系
     * @param apartmentLabelList
     */
    @AutoFill(OperationType.INSERT)
    void insertApartmentLabel(@Param("apartmentLabelList") List<ApartmentLabel> apartmentLabelList);

    /**
     * 插入公寓杂费关系
     * @param apartmentFeeValueList
     */
    @AutoFill(OperationType.INSERT)
    void insertApartmentFeeValue(@Param("apartmentFeeValueList") List<ApartmentFeeValue> apartmentFeeValueList);

    /**
     * 更新公寓信息
     * @param apartmentInfo
     */
    @AutoFill(OperationType.UPDATE)
    void updateApatrment(ApartmentInfo apartmentInfo);

    /**
     * 根据公寓id删除关联的图片
     * @param id
     */
    @Delete("delete from graph_info where item_type = 1 and item_id = #{id}")
    void deleteGraphinfo(Long id);

    /**
     * 根据公寓id删除
     * @param id
     */
    @Delete("delete from apartment_facility where apartment_id = #{id}")
    void deleteApartmentFacility(Long id);

    /**
     * 根据公寓id删除标签信息
     * @param id
     */
    @Delete("delete from apartment_label where apartment_id = #{id}")
    void deleteApartmentLabel(Long id);

    /**
     * 根据公寓id删除杂费值
     * @param id
     */
    @Delete("delete from apartment_fee_value where apartment_id = #{id}")
    void deleteApartmentFeeValue(Long id);

    /**
     * 条件分页查询
     * @param apartmentQueryVo
     * @return
     */
    Page<ApartmentItemVo> page(ApartmentQueryVo apartmentQueryVo);

    /**
     * 根据公寓id获取图片信息
     * @param id
     * @return
     */
    @Select("select name,url from graph_info where item_id = #{id}")
    List<GraphVo> getGraph(Long id);

    /**
     * 获取公寓信息
     * @param id
     * @return
     */
    @Select("select * from apartment_info where id = #{id}")
    ApartmentDetailVo getApartmentDetail(Long id);

    /**
     * 根据公寓id获取标签
     * @param id
     * @return
     */
    List<LabelInfo> getLabel(Long id);

    /**
     * 根据公寓id获取配套信息
     * @param id
     * @return
     */
    List<FacilityInfo> getFacilityInfo(Long id);

    /**
     * 根据公寓id查询杂费信息
     * @param id
     * @return
     */
    List<FeeValueVo> getFeeValue(Long id);

    /**
     * 删除公寓信息
     * @param id
     *
     */
    @Delete("delete from apartment_info where id = #{id}")
    void deleteApartment(Long id);

    /**
     * 根据区县id查询公寓信息列表
     * @param id
     * @return
     */
    @Select("select * from apartment_info where district_id = #{id}")
    List<ApartmentInfo> getApartmentByDistrictId(Long id);

    /**
     * 根据id获取公寓信息
     * @param apartmentId
     * @return
     */
    @Select("select * from  apartment_info where id = #{apartmentId}")
    ApartmentInfo getApartment(Long apartmentId);
}
